﻿function populateDatesForMonth(drpDay,mon,y) {
   
          if (y == "0000") {
        y = new Date().getFullYear();
    }
    //Clear previous options  
    try {
    drpDay.options.length = 0;

    var days = new Date(y, mon, 0).getDate();
   

    drpDay.options[0] = new Option("Day", 0);
    for (var i = 1; i <= days; i++) {
        drpDay.options[drpDay.options.length] = new Option(i, i);
    }
} catch (ex) { }
}


//function getQueryVariable(variable) {
//    var query = window.location.search.substring(1);
//    var vars = query.split("&");
//    for (var i = 0; i < vars.length; i++) {
//        var pair = vars[i].split("=");
//        if (pair[0] == variable) {
//            return pair[1];
//        }
//    }
//} 


//function SelectCss(MenuId) {
//  //  var query=<%=Request.QueryString["menuId"]%>;
//    var m = getQueryVariable("menuId");     
//    if (MenuId.id == m) {
//        document.getElementById(MenuId.id).className = "menu_selected";
//    }
//}

function selectAll(invoker) {

    // Since ASP.NET checkboxes are really HTML input elements

    //  let's get all the inputs 


    var inputElements = document.getElementsByTagName('input');



    for (var i = 0; i < inputElements.length; i++) {

        var myElement = inputElements[i];



        // Filter through the input types looking for checkboxes


        if (myElement.type === "checkbox") {



            // Use the invoker (our calling element) as the reference 

            //  for our checkbox status

            myElement.checked = invoker.checked;

        }

    }

}

function changeColor(sTemp) {
    try {
        if (sTemp.checked == true) {
            sTemp.parentElement.parentElement.style.backgroundColor = '#00FFFF';
        }
        else {
            sTemp.parentElement.parentElement.style.backgroundColor = 'white';
        }


        return false;
    }
    catch (err) { return false; }

}




function ValidateUser(key) {
    var keycode = (key.which) ? key.which : key.keyCode;
    //comparing pressed keycodes
    if ((keycode < 48 || keycode > 57)) {
        return true;
    }
    else {
        return false;
    }
}

function fnAlphabetRestict(e) {
    var code = e.keyCode ? event.keyCode : e.which ? e.which : e.charCode;
    if ((code >= 65 && code <= 90) || (code >= 97 && code <= 122) || code == 32 || code == 8 || code == 9 || code == 37 || code == 39 || code == 46 || code == 16 || code == 17 || code == 18 || code == 86 || code == 13) {
        checknos = true;
        return (checknos);
    }
    else {
        checknos = false;
        alert("Only Alphabates Allowed !");
        return (checknos);
    }
}

function fnNotAlphabet(e) {

    var code = e.keyCode ? event.keyCode : e.which ? e.which : e.charCode;

    //Code Explanation{ 0-9, 45=Insert, 13=Enter, 08=Backspace, 09=Tab}
 
    if ((code >= 48 && code <= 57) || code == 13 || code == 08 || code == 09 || code == 37 || code == 39 || code == 46 || code == 16 || code == 17 || code == 18 || code == 86) {
        checknos = true;
        return (checknos);
    }
    else {
        checknos = false;
        alert("Only Number Allowed !");
        return (checknos);
    }
}

function fnNumeric(e) {
    var code = e.keyCode ? event.keyCode : e.which ? e.which : e.charCode;

    //Code Explanation{ 0-9, 45=Insert, 13=Enter, 08=Backspace, 09=Tab}
    if (code >= 48 && code <= 57 || (code == 8 || code == 9 || code == 37 || code == 39 || code == 16 || code == 17 || code == 18 || code == 86 || code == 13)) {
        checknos = true;
        return (checknos);
    }
    else {
        checknos = false;
        alert("Only Number Allowed !");
        return (checknos);
    }
}


function fnAlphabetAndNumericWithSpace(e) {
    var code = e.keyCode ? e.keyCode : e.which ? e.which : e.charCode;
    //alert(code);


    if (e.shiftKey) {
        //alert("Shift + "+code);
        if ((code >= 65 && code <= 90 ) ) {
            checknos = true;
            return (checknos);
        }
        else {
            checknos = false;
            alert("Special characters are not allowed!");
            return (checknos);
        }
    }
    else {

        //if ((code >= 65 && code <= 90)||(code >= 97 && code <= 122) || code==32 || code==46 || code==8 || code==17 || code==127 || code==9 || code==16 || code==37 || code==38 || code==39 || code==40)		
        if ((code >= 65 && code <= 90) || (code >= 97 && code <= 122) || (code == 32) || (code == 8) || (code == 37) || (code == 39) || (code == 36) || (code == 40) || (code == 35) || code == 16 || code == 17 || code == 18 || code == 86 || code == 13) {
            checknos = true;
            return (checknos);
        }
        else {
            checknos = false;
            alert("Only Alphabates Allowed !");
            return (checknos);
        }
    }
}

function fnAddressValid(e) {
    var code = e.keyCode ? e.keyCode : e.which ? e.which : e.charCode;
    //	alert(code);
    //	return true;
    if ((code >= 65 && code <= 90) || (code >= 97 && code <= 122) || (code >= 37 && code <= 41) || (code >= 48 && code <= 57) || (code >= 44 && code <= 47) || (code == 32) || (code == 35) || (code == 38) || (code == 58) || (code == 64) || (code == 13) || (code == 08) || (code == 09) || code == 16 || code == 17 || code == 18 || code == 86) {
        checknos = true;
        return (checknos);
    }
    else {
        checknos = false;
        alert("Invalid character in address !");
        return (checknos);
    }
}


function fnAlplhaNumericOnly(e) {
    var code = e.keyCode ? e.keyCode : e.which ? e.which : e.charCode;
    //alert(code);
    if (e.shiftKey) {
        //alert("Shift + "+code);
        if ((code >= 65 && code <= 90) || code == 35 || code == 38 || code == 58 || code == 37 || code == 8 || code == 9 || code == 39 || code == 46 || code == 16 || code == 17 || code == 18 || code == 86 || code == 13) {
            checknos = true;
            return (checknos);
        }
        else {
            checknos = false;
            alert("Special characters are not allowed!");
            return (checknos);
        }
    }
    else {
        //alert(code);
        if ((code >= 65 && code <= 90) || (code >= 97 && code <= 122) || (code >= 48 && code <= 57) || (code == 13) || code == 32 || code == 46 || code == 8 || code == 17 || code == 127 || code == 9 || code == 16 || code == 37 || code == 38 || code == 39 || code == 47 || code == 92 || code == 35 || code == 44 || code == 45 || code == 40 || code == 41 || code == 36 || code == 16 || code == 18 || code == 86) {
            checknos = true;
            return (checknos);
        }
        else {
            checknos = false;
            alert("Special characters are not allowed!");
            return (checknos);
        }
    }
}

function fnAlplhaNumericOnlyWithoutSpeChar(e) {
    var code = e.keyCode ? e.keyCode : e.which ? e.which : e.charCode;

    if (e.shiftKey) {
        //alert("Shift + "+code);
        if ((code >= 65 && code <= 90)) {
            checknos = true;
            return (checknos);
        }
        else {
            checknos = false;
            alert("Special characters are not allowed!");
            return (checknos);
        }
    }
    else {

        if ((code >= 65 && code <= 90) || (code >= 97 && code <= 122) || (code >= 48 && code <= 57) || code == 8 || code == 35 || code == 36 || code == 37 || code == 39 || code == 16 || code == 17 || code == 18 || code == 86 || code == 13) {
            checknos = true;
            return (checknos);
        }

        else {
            checknos = false;
            alert("Only Alphanumeric Allowed !");
            return (checknos);
        }
    }
}


function fnValidatePassportNo(e) {
    //	var code = e.keyCode ? e.keyCode : e.which ? e.which : e.charCode;

    var b = navigator.appName;
    var version = navigator.appVersion;
    //	 alert(b);
    //	 alert(version);

    if (b == "Microsoft Internet Explorer") {
        var code = e.keyCode;
    }
    else if (b == "Netscape") {
        var code = e.which;
    }
    else if (b == "Opera" && (version == "9.80 (Windows NT 5.1; U; en)" || version == "9.64 (Windows NT 5.1; U; en)")) {
        var code = e.which;
        //alert(code);
    }

    if (e.shiftKey) {
        //alert("Shift + "+code);
        if ((code >= 65 && code <= 90)) {
            checknos = true;
            return (checknos);
        }
        else {
            checknos = false;
            alert("Special characters are not allowed!");
            return (checknos);
        }
    }

    else {
        if (b == "Microsoft Internet Explorer") {

            if ((code >= 65 && code <= 90) || (code >= 97 && code <= 122) || (code >= 48 && code <= 57) || code == 32 || code == 8 || code == 127 || code == 9 || code == 16 || code == 37 || code == 35 || code == 36 || code == 58 || code == 17 || code == 18 || code == 86 || code == 13) {

                checknos = true;
                return (checknos);
            }
            else {
                checknos = false;
                alert("Only Alphabates Allowed !");
                return (checknos);

            }
        }

        else if (b == "Netscape") {

            if ((code >= 65 && code <= 90) || (code >= 97 && code <= 122) || (code >= 48 && code <= 57) || code == 32 || code == 8 || code == 127 || code == 9 || code == 37 || code == 35 || code == 36 || code == 58 || code == 0 || code == 13 || code == 16 || code == 17 || code == 18 || code == 86) {

                checknos = true;
                return (checknos);
            }
            else {
                checknos = false;
                alert("Only Alphabates Allowed !");
                return (checknos);

            }

        }

        if (b == "Opera") {
            if ((code >= 65 && code <= 90) || (code >= 97 && code <= 122) || (code >= 48 && code <= 57) || code == 32 || code == 8 || code == 127 || code == 9 || code == 37 || code == 35 || code == 36 || code == 58 || code == 0 || code == 13 || code == 16 || code == 17 || code == 18 || code == 86) {

                checknos = true;
                return (checknos);
            }
            else {
                checknos = false;
                alert("Only Alphabates Allowed !");
                return (checknos);

            }
        }

    }


}

function chkfeb(id) {

    try {
        var year = document.getElementById(id + "_drpYear").value;
        if (document.getElementById(id + "_drpDay").options.length == 30) {
            document.getElementById(id + "_drpDay").options[30] = new Option('30', '30');
            document.getElementById(id + "_drpDay").options[31] = new Option('31', '31');
        }
        else if (document.getElementById(id + "_drpDay").options.length == 29) {
            document.getElementById(id + "_drpDay").options[29] = new Option('29', '29');
            document.getElementById(id + "_drpDay").options[30] = new Option('30', '30');
            document.getElementById(id + "_drpDay").options[31] = new Option('31', '31');
        }

        if (document.getElementById(id + "_drpMonth").value == "2") {

            if (document.getElementById(id + "_drpDay").options.length == 32) {
                if ((year % 4) == 0) {
                    document.getElementById(id + "_drpDay").options[31] = null;
                    document.getElementById(id + "_drpDay").options[30] = null;
                }
                else {
                    document.getElementById(id + "_drpDay").options[31] = null;
                    document.getElementById(id + "_drpDay").options[30] = null;
                    document.getElementById(id + "_drpDay").options[29] = null;
                }
            }
            else {
                if ((year % 4) == 0) {

                    document.getElementById(id + "_drpDay").options[30] = null;
                }
                else {
                    document.getElementById(id + "_drpDay").options[30] = null;
                    document.getElementById(id + "_drpDay").options[29] = null;
                }

            }
        }

        else if ((document.getElementById(id + "_drpMonth").value == "4") || (document.getElementById(id + "_drpMonth").value == "6") || (document.getElementById(id + "_drpMonth").value == "9") || (document.getElementById(id + "_drpMonth").value == "11")) {
            document.getElementById(id + "_drpDay").options[31] = null;
        }
        else {
            if (document.getElementById(id + "_drpDay").options.length != "32")
                document.getElementById(id + "_drpDay").options[31] = new Option('31', '31');
        }
        if ((id == "ctl00_ctl00_MainContent_QueryForm_ucChild_ucChildPlnParentDateOfBirth" || id == "ctl00_ctl00_MainContent_QueryFormInvestMent_ucChildPlnParentDateOfBirth") && (document.getElementById(id + "_drpDay").selectedIndex > 0) && (document.getElementById(id + "_drpMonth").selectedIndex > 0) && (document.getElementById(id + "_drpYear").selectedIndex > 0)) {
            //alert("Agrawal");
            CallChildAge();
        }
    } catch (ex) { }

}


function fnNotAlphabetandZeroPincode(e, obj) {
    var controlId = obj.id;
    var code = e.keyCode ? event.keyCode : e.which ? e.which : e.charCode;

    //Code Explanation{ 0-9, 45=Insert, 13=Enter, 08=Backspace, 09=Tab}
    if ((code >= 48 && code <= 57) || (code == 13 || code == 08 || code == 09 )) {
        if (document.getElementById(controlId).value.length == 0 && code == 48) {
            checknos = false;
            alert("- Pin Code can not start with 0!");
            return (checknos);
        }

        else {
            checknos = true;
            return (checknos);
        }
    }
    else {
        checknos = false;

        alert("Only Number Allowed !");
        return (checknos);
    }

}

function fnContactNumber(obj) {

    if (obj.value.length > 0) {
        if (isNaN(obj.value) == false) {
            if (obj.value.length >= 4 && obj.value.length <= 10) {
                if (obj.value == "00" || obj.value == "000" || obj.value == "0000" || obj.value == "00000") {
                    alert("- Only Zero Not Allowed in STD Code!");
                    obj.value = "";
                    obj.focus();
                    return false;
                }
            }
            else {
                alert("- Enter Valid Contact Number!");
                obj.value = "";
                obj.focus();
                return false;
            }
        }
        else {
            alert("Only Number Allowed !");
            obj.value = "";
            obj.focus();
            return false;
        }
        return true;
    }
    return true;
}


function fnValidate() {

    var alertMsg = '';
    var mainMsg = 'Please provide correct information for the following fields highlighted in red: \n \n';

    var idx;
    var TagName;
    var labelId = new Array();
    var tdId = new Array();
    var emailIdx;
    var countControl=0;
    
    for (var j = 0; j < document.forms[0].elements.length; j++) {


        if ((document.forms[0].elements[j].type == "text" || document.forms[0].elements[j].type == "select-one" || document.forms[0].elements[j].type == "select-multiple" || document.forms[0].elements[j].type == "password" || document.forms[0].elements[j].type == "textarea") && document.forms[0].elements[j].TagName != "Not" && document.forms[0].elements[j].TagName != "Select" && document.forms[0].elements[j].TagName != "Day" && document.forms[0].elements[j].TagName != "Month" && document.forms[0].elements[j].TagName != "Year" && document.forms[0].elements[j].style.visibility != "hidden") {

            idx = j;
            if (countControl == 0) {
                countControl = idx;
            }

            if (labelId.length == 0) {
                for (var tdCount = 0; tdCount < document.getElementsByTagName('td').length; tdCount++) {
                    if (document.getElementsByTagName('td')[tdCount].style.visibility != "hidden" && document.getElementsByTagName('td')[tdCount].id != '' && document.getElementsByTagName('td')[tdCount].id != "tdDate" && document.getElementsByTagName('td')[tdCount].id.substring(0, 3) != "scw") {
                        tdId[idx] = document.getElementsByTagName('td')[tdCount].id;
                        labelId[idx] = tdCount;
                        var emailId = tdId[idx];
                        if (emailId.indexOf("Email") != -1) {
                            emailIdx = idx;
                        }
                        idx++;

                    }
                }

            }


            if ((document.forms[0].elements[j].value == '' || document.forms[0].elements[j].value == '0') && document.forms[0].elements[j].TagName != "Not" && document.forms[0].elements[j].TagName != undefined && document.forms[0].elements[j].style.visibility != "hidden") {

                TagName = document.forms[0].elements[j].TagName;
                alertMsg = alertMsg + TagName + "\n";
                document.getElementsByTagName('td')[labelId[countControl]].style.color = 'red';

                countControl++;

            }
            else if (document.forms[0].elements[j].value != '' && document.forms[0].elements[j].TagName != "Not" && document.forms[0].elements[j].TagName != undefined) {
                document.getElementsByTagName('td')[labelId[countControl]].style.color = 'black';


                countControl++;
            }



            //    Email Validation

            if (document.forms[0].elements[j].value != '' && document.forms[0].elements[j].type == "text" && document.forms[0].elements[j].TagName.indexOf("Email") != -1 && document.forms[0].elements[j].TagName != undefined && document.forms[0].elements[j].style.visibility != "hidden") {
                var pattern = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/;
                var emailid = document.forms[0].elements[j].value;
                var matcharray = emailid.match(pattern);
                if (matcharray == null) {

                    alertMsg = alertMsg + "Enter Correct Email Id \n";
                    document.getElementsByTagName('td')[labelId[emailIdx]].style.color = 'red';
                }
                else {
                    document.getElementsByTagName('td')[labelId[emailIdx]].style.color = 'black';
                }
            }



            //end if       
        }
        
//        else {

//            // check date of birth

//            if (document.forms[0].elements[j].type == "select-one") {
//                if (document.forms[0].elements[j].TagName == "Select" || document.forms[0].elements[j].TagName == "Day" || document.forms[0].elements[j].TagName == "Month" || document.forms[0].elements[j].TagName == "Year") {

//                    if (document.forms[0].elements[j].value == '0' || document.forms[0].elements[j].value == '0000') {
//                        TagName = document.forms[0].elements[j].TagName;
//                        alertMsg = alertMsg + "Select Date of Birth-"+TagName+ "\n";
//                        document.getElementById('tdDate').style.color = 'red';

//                    }
//                    else {
//                        document.getElementById('tdDate').style.color = 'black';
//                    }
//                }
//            }
            //        }

       

            //end for
        }
                      
                       //Set hidden field control to black
                       for (var tdIdx = 0; tdIdx < document.getElementsByTagName('td').length; tdIdx++) {
                           if (document.getElementsByTagName('td')[tdIdx].style.visibility == "hidden" && document.getElementsByTagName('td')[tdIdx].id != '') {
                               document.getElementsByTagName('td')[tdIdx].style.color = 'black';
                           }
                       }

                       if (alertMsg.length > 1) {
                           mainMsg = mainMsg + alertMsg;
                           alert(mainMsg);
                           return false;
                       }
                       else return true;

       
    }



    function RefreshReminders() {

        try {

            window.opener.$("#MainContent_MyLeadsCtrl_AlarmMylead_refereshbtn").click();
            window.opener.$("#MainContent_Alarm2_refereshbtn").click();
        }
        catch (Error) {
        }

    }




    function BlockScreen() {
        $("#modal").show();
    }


    function checkFileExtension(elem) {
        var filePath = elem.value;

        if (filePath.indexOf('.') == -1)
            return false;

        var validExtensions = new Array();
        var ext = filePath.substring(filePath.lastIndexOf('.') + 1).toLowerCase();
        validExtensions[0] = 'jpg';
        validExtensions[1] = 'jpeg';
        validExtensions[2] = 'bmp';
        //         validExtensions[3] = 'png';
        //         validExtensions[4] = 'gif'; 

        for (var i = 0; i < validExtensions.length; i++) {
            if (ext == validExtensions[i])
                return true;
        }

        alert('The file extension ' + ext.toUpperCase() + ' is not allowed!');

        var newInput = document.createElement("input");

        newInput.type = "file";
        newInput.id = elem.id;
        newInput.name = elem.name;
        if (newInput.addEventListener) {
            newInput.onchange = new Function("return checkFileExtension(this);");
        } else {
            newInput.setAttribute('onchange', "return checkFileExtension(this);");
        }

        elem.parentNode.replaceChild(newInput, elem);
        return false;
    }



    function checkFileExtensionUserImage(elem) {
        var filePath = elem.value;

        if (filePath.indexOf('.') == -1)
            return false;

        var validExtensions = new Array();
        var ext = filePath.substring(filePath.lastIndexOf('.') + 1).toLowerCase();
        validExtensions[0] = 'jpg';
        validExtensions[1] = 'jpeg';
        validExtensions[2] = 'bmp';
        validExtensions[3] = 'png';
        validExtensions[4] = 'gif'; 

        for (var i = 0; i < validExtensions.length; i++) {
            if (ext == validExtensions[i])
                return true;
        }

        alert('The file extension ' + ext.toUpperCase() + ' is not allowed!');

        var newInput = document.createElement("input");

        newInput.type = "file";
        newInput.id = elem.id;
        newInput.name = elem.name;
        if (newInput.addEventListener) {
            newInput.onchange = new Function("return checkFileExtension(this);");
        } else {
            newInput.setAttribute('onchange', "return checkFileExtension(this);");
        }

        elem.parentNode.replaceChild(newInput, elem);
        return false;
    }

    function checkFileExtensionNotes(elem) {
        var filePath = elem.value;

        if (filePath.indexOf('.') == -1)
            return false;

        var validExtensions = new Array();
        var ext = filePath.substring(filePath.lastIndexOf('.') + 1).toLowerCase();
        validExtensions[0] = 'jpg';
        validExtensions[1] = 'jpeg';
        validExtensions[2] = 'bmp';
                 validExtensions[3] = 'png';
                 validExtensions[4] = 'gif';
                 validExtensions[5] = 'docx';
                 validExtensions[6] = 'doc';
                 validExtensions[7] = 'txt';
                 validExtensions[8] = 'xls';
                 validExtensions[9] = 'xlsx';
                 validExtensions[10] = 'pdf'; 

        for (var i = 0; i < validExtensions.length; i++) {
            if (ext == validExtensions[i])
                return true;
        }

        alert('The file extension ' + ext.toUpperCase() + ' is not allowed!');

        var newInput = document.createElement("input");

        newInput.type = "file";
        newInput.id = elem.id;
        newInput.name = elem.name;
        if (newInput.addEventListener) {
            newInput.onchange = new Function("return checkFileExtension(this);");
        } else {
            newInput.setAttribute('onchange', "return checkFileExtension(this);");
        }

        elem.parentNode.replaceChild(newInput, elem);
        return false;
    }

//    function Validate_YouTubeUrl(val) {
//        var reg = /^http:\/\/(?:www\.)?youtube.com\/embed\/\?(?=.*v=\w+)(?:\S+)?$/;
//        alert(val);
//        if (val != '') {
//            if (reg.test(val) == true) {
//                alert('Url');
//            } else {
//                alert('Url is invalid');
//            }
//        }
//    }